
// Load plugins
var gulp          = require('gulp'),                   //gulp
    minifycss     = require('gulp-minify-css'),        //CSS压缩
    uglify        = require('gulp-uglify'),            //js压缩
    imagemin      = require('gulp-imagemin'),          //img压缩
    pngquant      = require('imagemin-pngquant'),      //img压缩
    minifyHTML    = require('gulp-minify-html'),       //html压缩
    usemin        = require('gulp-usemin');            //替换css、js路径




// 配置参数
var baseUrl = {
    src: './sdk_src',
    dist: './sdk'
}


//替换appjs路径
gulp.task('usemin', function() {
  return gulp.src(baseUrl.src + '/*.html')
    .pipe(usemin({
      css: [ minifycss ],  
      js: [ uglify({
        compress: {
            drop_console: true
        }
      }) ],
      plugins: [ uglify({
        compress: {
            drop_console: true
        }
      }) ],
      common: [ uglify({
        compress: {
            drop_console: true
        }
      }) ]
    }))
    .pipe(gulp.dest(baseUrl.dist + '/'));
});


// Images
gulp.task('images', function() {
    return gulp.src(baseUrl.src + '/images/**/*')
    .pipe(imagemin({
        progressive: true,
        svgoPlugins: [{removeViewBox: false}],
        use: [pngquant()]
    }))
    .pipe(gulp.dest(baseUrl.dist + '/images'))
});


//Html copy
gulp.task('html', function () {
    return gulp.src(baseUrl.src + '/*.html')
    .pipe(gulp.dest(baseUrl.dist + '/'))
});


//Tpls copy
gulp.task('tpls', function () {
    return gulp.src(baseUrl.src + '/tpls/**/*')
    .pipe(minifyHTML({ empty: true }))
    .pipe(gulp.dest(baseUrl.dist + '/tpls'))
});


// Styles copy
gulp.task('styles', function () {
    return gulp.src(baseUrl.src + '/styles/plugins/**/*')
    .pipe(gulp.dest(baseUrl.dist + '/styles/plugins/'))
});


// Scripts copy
gulp.task('scripts', function () {
    return gulp.src(baseUrl.src + '/scripts/**/*')
    .pipe(gulp.dest(baseUrl.dist + '/scripts/'))
});


// Modules copy
gulp.task('modules', function () {
    return gulp.src(baseUrl.src + '/modules/**/*')
    .pipe(gulp.dest(baseUrl.dist + '/modules/'))
});

// 生产环境 
gulp.task('default', ['images', 'html', 'tpls', 'styles', 'scripts', 'modules', 'usemin']);